package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzTixx;
import com.ruoyi.system.service.IDzTixxService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题库选项Controller
 * 
 * @author ruoyi
 * @date 2022-09-02
 */
@RestController
@RequestMapping("/api/tixx")
public class DzTixxApiController extends BaseController
{
    @Autowired
    private IDzTixxService dzTixxService;

    /**
     * 查询题库选项列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzTixx dzTixx)
    {
        startPage();
        List<DzTixx> list = dzTixxService.selectDzTixxListWeb(dzTixx);
        return getDataTable(list);
    }

    /**
     * 导出题库选项列表
     */
    @Log(title = "题库选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzTixx dzTixx)
    {
        List<DzTixx> list = dzTixxService.selectDzTixxListWeb(dzTixx);
        ExcelUtil<DzTixx> util = new ExcelUtil<DzTixx>(DzTixx.class);
        util.exportExcel(response, list, "题库选项数据");
    }

    /**
     * 获取题库选项详细信息
     */
    @GetMapping(value = "/{xxId}")
    public AjaxResult getInfo(@PathVariable("xxId") Long xxId)
    {
        return AjaxResult.success(dzTixxService.selectDzTixxByXxId(xxId));
    }

    /**
     * 新增题库选项
     */
    @Log(title = "题库选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzTixx dzTixx)
    {
        return toAjax(dzTixxService.insertDzTixx(dzTixx));
    }

    /**
     * 修改题库选项
     */
    @Log(title = "题库选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzTixx dzTixx)
    {
        return toAjax(dzTixxService.updateDzTixx(dzTixx));
    }

    /**
     * 删除题库选项
     */
    @Log(title = "题库选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{xxIds}")
    public AjaxResult remove(@PathVariable Long[] xxIds)
    {
        return toAjax(dzTixxService.deleteDzTixxByXxIds(xxIds));
    }
}
